from django.contrib import admin

from django.contrib.admin.widgets import AdminFileWidget
from django.utils.safestring import mark_safe
from django.db import models
from models import Album,Photo


class AdminPhotoWidget(AdminFileWidget):
    def render(self,name,value,attrs=None):
        output = []
        if value and hasattr(value, "url"):
            output.append('%s <a target="_blank" href="%s"><img src = "%s" /></a> <br />%s ' % \
                (_('Currently:'), value.url, value, _('Change:')))
        output.append(super(AdminFileWidget, self).render(name, value, attrs))
        return mark_safe(u''.join(output))

class PhotoAdmin(admin.ModelAdmin):
    pass

class AlbumAdmin(admin.ModelAdmin):    
    pass

admin.site.register(Photo,PhotoAdmin)
admin.site.register(Album,AlbumAdmin)
